<template>
  <div class="wrap">
    <form action method onsubmit="return false" enctype="multipart/form-data">
      <div class="box">
        <label for>请输入原密码:</label>
        <input class="input" type="password" v-model="password_old" />
      </div>
      <div class="box">
        <label for>请输入新密码:</label>
        <input class="input" type="password" v-model="password_new" />
      </div>
      <div class="box">
        <label for>请再次输入新密码:</label>
        <input class="input" type="password" v-model="password_re" />
      </div>
      <div class="btn" @click="oBtn()">
        <input type="submit" value="保存" style="cursor:pointer"/>
      </div>
    </form>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data () {
    return {
      num: 654,
      password_old: '',
      password_new: '',
      password_re: '',
      id: null
    }
  },
  computed: {},
  watch: {},
  methods: {
    oBtn () {
      if (this.password_new !== this.password_re) {
        alert('新密码不相符！')
        return
      }
      if (this.password_old === '' || this.password_new === '' || this.password_re === '') {
        alert('不可为空！')
        return
      }
      let _this = this
      this.$http({
        method: 'post',
        url: 'v1/login/update-pwd',
        data: {
          id: _this.id,
          password_old: _this.password_old,
          password_new: _this.password_new,
          password_re: _this.password_re
        }
      }).then(res => {
        alert(res.data.data.msg)
        _this.$router.push({
          name: 'login'
        })
      })
        .catch(err => {
          console.log(err)
        })
    },
    sendMsgToParent () {
      this.$emit('listenToChildExen', this.num)
    }
  },
  created () {
    this.id = sessionStorage.id
  },
  mounted () {
    this.sendMsgToParent()
  }
}
</script>

<style lang='scss' scoped>
.wrap {
  width: 934px;
  height: 654px;
  background-color: #ffffff;
  padding-top: 36px;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: flex-start;

  form {
    .box {
      width: 100%;
      margin-bottom: 30px;
      label {
        font-family: "MicrosoftYaHei";
        font-size: 16px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 40px;
        letter-spacing: 0px;
        color: #333333;
        width: 133px;
        height: 40px;
        text-align: right;
        display: inline-block;
      }

      .input {
        width: 400px;
        height: 40px;
        background-color: #ffffff;
        border-radius: 5px;
        border: solid 1px #dbdbda;
        outline: none;
        margin-left: 30px;
      }
    }

    .btn {
      display: flex;
      justify-content: center;
      margin-top: 60px;

      input[type="submit"] {
        width: 230px;
        height: 63px;
        background-color: #e60012;
        border-radius: 5px;
        font-family: "MicrosoftYaHei";
        font-size: 26px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 63px;
        text-align: center;
        letter-spacing: 0px;
        color: #ffffff;
        outline: none;
      }
    }
  }
}
</style>
